<template>
  <div>
    <!-- 延期表单 -->
    <el-form ref="form" :model="postponeForm" :inline="true" :rules="rules" label-width="120px">
      <el-row>
        <el-col :span="24">
          <el-table :data="postponeForm.certInfoList" max-height="350" >
            <el-table-column label="序号" align="center" type="index" :show-overflow-tooltip="false"/>
            <el-table-column
              label="工号"
              align="center"
              prop="staffNo"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="姓名"
              align="center"
              prop="username"
              :show-overflow-tooltip="true"
            />
            <!--<el-table-column
              label="部门"
              align="center"
              prop="deptName"
              :show-overflow-tooltip="true"
            />-->

            <el-table-column
              label="编号"
              align="center"
              prop="certNumber"
              :show-overflow-tooltip="true"
            />

            <!--<el-table-column
              label="证书名称"
              align="center"
              prop="certName"
              :show-overflow-tooltip="true"
            />-->

            <el-table-column
              label="项目代码"
              align="center"
              prop="projectCode"
            />

            <el-table-column label="取证日期" align="center" prop="obtainEvidenceDate" width="100px">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.obtainEvidenceDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>

            <el-table-column label="到期日期" align="center" prop="endDate" width="100px">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>

            <!--<el-table-column
              label="有效期（年）"
              align="center"
              prop="reviewPeriod"
            />-->

            <!--<el-table-column
              label="取证状态"
              align="center"
              prop="getCertStatus"
              :formatter="getStatusFormat"
            />

            <el-table-column
              label="证书来源"
              align="center"
              prop="certSource"
              :formatter="certSourceFormat"
            />

            <el-table-column
              label="证书状态"
              align="center"
              prop="certStatus"
              :formatter="certStatusFormat"
            />-->
          </el-table>
        </el-col>
      </el-row>

      <el-row style="margin-top: 20px">
        <el-col :span="12">
          <el-form-item label="延期原因" prop="cause">
            <el-input
              v-model="postponeForm.cause"
              placeholder="请输入原因"
              clearable
              size="small"
            />
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    <div class="dialog-footer" style="float:right">
      <el-button :loading="buttonLoading" type="primary" @click="submitForm('submit')">提交</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
  import {postponeCert} from "@/api/cert/certInfo";

  export default {
    name: "postponeForm",
    props: {
      // 延期表单信息
      postponeForm: Object,
    },
    data() {
      return {
        // 按钮loading
        buttonLoading: false,
        // 表单校验
        rules: {
          cause: [
            {required: true, message: "原因不能为空", trigger: "blur"}
          ],
        },
        // 取证状态数据字典
        getCertStatusOptions: [],
        // 证书来源数据字典
        certSourceOptions: [],
        // 证书状态数据字典
        certStatusOptions: [],
      }
    },
    created() {
      //查询取证状态字典状态
      /*this.getDicts("cert_get_status").then(response => {
        this.getCertStatusOptions = response.data;
      });
      //查询证书来源字典状态
      this.getDicts("cert_source").then(response => {
        this.certSourceOptions = response.data;
      });
      //查询证书字典状态
      this.getDicts("cert_status").then(response => {
        this.certStatusOptions = response.data;
      });*/
    },
    methods: {
      // 取证状态字典翻译
      /*getStatusFormat(row, column) {
        return this.selectDictLabel(this.getCertStatusOptions, row.getCertStatus);
      },

      // 证书来源字典翻译
      certSourceFormat(row, column) {
        return this.selectDictLabel(this.certSourceOptions, row.certSource);
      },

      // 证书状态字典翻译
      certStatusFormat(row, column) {
        return this.selectDictLabel(this.certStatusOptions, row.certStatus);
      },*/

      /** 延期提交按钮 */
      submitForm(flag) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.postponeForm.certInfoList != null) {
              postponeCert(this.postponeForm).then(response => {
                if (response.responseBody > 0)
                  this.msgSuccess("提交成功");
                else this.msgError(response.message);
                // 关闭对话框
                this.$emit("cancelDialog");
                //刷新数据
                this.$emit("submitForm")
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },

      // 取消按钮
      cancel() {
        // 清空
        this.$emit("cancelDialog");
      },
    }

  }

</script>
